﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace UnliQ.Web.Models
{
    public class GridViewData<T>
    {
        public int total { get; set; }
        public int page { get; set; }
        public int records { get; set; }
        public List<T> rows { get; set; }
        public bool isSuccessful { get; set; }
        public string errorMessage { get; set; }
    }

    public class GridViewDataGenerator<T>
    {
        public static void GenerateGridViewData(ref GridViewData<T> gridViewData, List<T> list, int pageIndex, int pageSize)
        {
            int totalRecords = list.Count();
            var gridData = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

            gridViewData.rows = gridData;
            gridViewData.total = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
            gridViewData.records = totalRecords;
            gridViewData.isSuccessful = true;
            gridViewData.page = pageIndex;
        }

        public static void GenerateGridViewData(ref GridViewData<T> gridViewData, List<T> list)
        {
            gridViewData.rows = list;
            gridViewData.isSuccessful = true; ;
        }
    }
}